<template>
	<jk-dialog
		v-model="showDialog"
		:title="`详情-${dataItem.deviceRecordNumber}`"
		width="1100px"
		:show-content-loading="showLoading"
		append-to-body
		:show-close-btn="true"
		:show-confirm-btn="false"
		:show-cancel-btn="false"
		@on-close="onVisibleChange(false)"
		@on-visible-change="onVisibleChange"
	>
		<el-form ref="ruleForm" :model="ruleForm" label-width="110px" :show-message="false">
			<el-row ref="box1">
				<el-col :span="8">
					<el-form-item class="margin-bottom-10" label="设备">
						<span class="read-only-2">{{ dataItem.deviceRecordNumber }}</span>
					</el-form-item>
				</el-col>
				<el-col :span="8">
					<el-form-item class="margin-bottom-10" label="工序">
						<span class="read-only-2">{{ dataItem.processName }}</span>
					</el-form-item>
				</el-col>
				<el-col :span="8">
					<el-form-item class="margin-bottom-10" label="区域">
						<span class="read-only-2">{{ dataItem.workshopName }}</span>
					</el-form-item>
				</el-col>
				<el-col :span="8">
					<el-form-item class="margin-bottom-10" label="时间">
						<span class="read-only-2">{{ dataItem.belongDateTime }}</span>
					</el-form-item>
				</el-col>
			</el-row>
		</el-form>
		<jk-table :data="tableData" :height="dialogTableHeight - 30">
			<!--<vxe-column title="设备" align="left" fixed="left" field="deviceRecordNumber" :width="80" />-->
			<vxe-column title="纱种" fixed="left" align="left" field="yarnSeed" :width="220" />
			<vxe-column title="锭数" align="left" field="numberIngots" :width="100" />
			<!--<vxe-column title="工序" sortable align="left" field="processName" :width="70" />-->
			<!--<vxe-column title="区域" sortable align="left" field="workshopName" :width="90" />-->
			<vxe-column title="班次" sortable align="left" field="groupName" :width="90" />
			<!--<vxe-column title="当班开始表数(kg)" align="right" field="startOutputKg" :min-width="120" />-->
			<!--<vxe-column title="当班实时表数(kg)" align="right" field="endOutputKg" :min-width="120" />-->
			<vxe-column title="当班开始产量表数(米)" align="right" field="startOutputM" :min-width="140" />
			<vxe-column title="当班实时产量表数(米)" align="right" field="endOutputM" :min-width="140" />

			<vxe-column title="当班开始能耗(KW.H)表数" align="right" field="startEnergy" :min-width="160" />
			<vxe-column title="当班实时能耗(KW.H)表数" align="right" field="endEnergy" :min-width="160" />
			<vxe-column title="总能耗(KW.H)表数" align="right" field="totalEnergy" :min-width="160" />

			<vxe-column title="当班产量(米)" align="right" field="outputM" :width="110" />
			<vxe-column title="当班产量(kg)" align="right" field="outputKg" :width="130" />
			<vxe-column title="当班能耗(KW.H)" align="right" field="energy" :width="130"></vxe-column>
			<!--<vxe-column title="时间" align="left" field="belongDateTime" :width="180" />-->
		</jk-table>
	</jk-dialog>
</template>

<script>
    import calHeight from '/src/mixins/cal-dialog-height';
    import { formatDate } from '../../../../utils/jk/jk-tool';
    import { iotCollectDataCountInfo } from '../../../../api/production/frontGroupYieldStatistics';
    export default {
        props: {
            dialogState: {
                type: Boolean,
                default: false
            },
            searchParams: {
                type: Object,
                default() {
                    return {};
                }
            },
            dataItem: {
                type: Object,
                default() {
                    return {};
                }
            }
        },
        mixins: [calHeight],
        data() {
            return {
                tableData: [],
                showDialog: false,
                showLoading: true,
                ruleForm: {}
            };
        },
        methods: {
            onVisibleChange(e) {
                this.$emit('on-visible-change', e);
                if (!e) {
                    Object.assign(this.$data, this.$options.data());
                    this.$nextTick(() => {
                        this.$refs.ruleForm.resetFields();
                    });
                }
            },
            getDetailRequest() {
                this.showLoading = true;
                return iotCollectDataCountInfo({
                    deviceRecordId: this.dataItem.deviceRecordId,
                    belongDate: formatDate(this.dataItem.belongDateTime),
                    groupId: this.searchParams.groupId
                }).then(res => {
                    this.showLoading = false;
                    if (res.data.status === 200) {
                        this.tableData = res.data.res;
                    }
                });
            }
        },
        watch: {
            dialogState(newVal) {
                this.showDialog = newVal;
                if (newVal) {
                    this.getDetailRequest();
                }
            }
        }
    };
</script>
